package com.xiaoyu.lanling.feature.chat.viewholder

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageButton
import android.widget.TextView
import com.facebook.drawee.view.SimpleDraweeView
import com.qmuiteam.qmui.widget.QMUILoadingView
import com.xiaoyu.im.datamodel.MessageDisplayStatus
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.feature.chat.model.message.ChatMessageSendGiftItem
import com.xiaoyu.lanling.media.image.ImageViewUtil
import com.xiaoyu.lanling.view.UserAvatarDraweeView

class ChatMessageSendGiftViewHolder : ChatMessageBaseReceiveSendViewHolder<ChatMessageSendGiftItem>() {

    private var mView: View? = null
    private var mFail: ImageButton? = null
    private var mLoading: QMUILoadingView? = null
    private var mGiftLayout: FrameLayout? = null
    private var mGiftIconView: SimpleDraweeView? = null
    private var mTitle: TextView? = null
    private var mContent: TextView? = null

    override fun doCreateChildrenView(layoutInflater: LayoutInflater, parent: ViewGroup): View? {
        mView = layoutInflater.inflate(R.layout.item_chat_send_gift, parent, false)
        mFail = mView?.findViewById(R.id.chat_send_fail)
        mLoading = mView?.findViewById(R.id.chat_send_loading)
        mGiftLayout = mView?.findViewById(R.id.chat_message_gift_layout)
        mGiftIconView = mView?.findViewById(R.id.chat_message_gift_icon)
        mTitle = mView?.findViewById(R.id.chat_message_gift_title)
        mContent = mView?.findViewById(R.id.chat_message_gift_content)
        return mView
    }

    override fun showData(position: Int, itemData: ChatMessageSendGiftItem) {
        super.showData(position, itemData)

        if (itemData.messageDisplayStatus == MessageDisplayStatus.SENDING) {
            mLoading?.visibility = View.VISIBLE
            mFail?.visibility = View.GONE
        } else if (itemData.messageDisplayStatus == MessageDisplayStatus.NORMAL_FAIL) {
            mFail?.setImageResource(R.drawable.icon_chat_send_fail)
            mFail?.visibility = View.VISIBLE
            mLoading?.visibility = View.GONE
        } else {
            mFail?.visibility = View.GONE
            mLoading?.visibility = View.GONE
        }
        ImageViewUtil.loadImage(mGiftIconView, itemData.imageLoadParam)
        mTitle?.text = itemData.title
        mContent?.text = itemData.content
//        ChatMessageGiftItemClickHandler.bindSendGiftItemClickForViewAndData(mGiftLayout, itemData)
//        ChatMessageSendFailClickHandler.bindGiftSendFailClickForViewAndData(mFail, itemData)
    }
}